<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<div id="userMenu" class="easyui-menu" data-options="onClick:menuHandler" style="width:120px;display: none">
		<div data-options="name:'save',iconCls:'icon-save'">启用</div>
		<div data-options="name:'del',iconCls:'icon-remove'">禁用</div>
		<div data-options="name:'exit'">取消</div>
	</div>
<table id="userData"></table>
<div id="userGrid_bar" >
	<form id="searchForm" method="post" style="padding: 10px;]">  
	    <div>  
	    <label for="uId">用户ID:</label>  
	        <input class="easyui-validatebox" type="text" name="uId" />
	        <label for="uName">用户名:</label>  
	        <input class="easyui-validatebox" type="text" name="uName" />  
	        <label for="uEmail">邮箱:</label>  
	        <input class="easyui-validatebox" type="text" name="uEmail" data-options="validType:'email'" /> 
	        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitForm()">搜索一下</a>
	        --搜索条件可以选填。 
	     </div>
	  
	</form>
</div>
<script type="text/javascript">
		/* 读取用户信息并设置到表格 */
		 var userData;
		 userData=$('#userData').datagrid({
			url:'user/getUserList',
			striped:true,
			loadMsg:"正在加载中...",
			pagination:true,
			pageNumber:1,
			pageSize:10,
			pageList:[10,20,30,40,50],
			remoteSort:false,
			fit:true,
			toolbar:"#userGrid_bar",
			columns:[[
			      	{field:'',align:'center',checkbox:true},
			      	{field:'uId',title:'用户ID',width:180,align:'center'},
			  		{field:'uName',title:'用户名',width:180,align:'center'},
			  		{field:'uEmail',title:'邮箱',width:180,align:'center'},
			  		{field:'uPhone',title:'联系方式',width:180,align:'center'},
			  		{field:'uAddress',title:'上次登陆ip',width:180,align:'center'},
			  		{field:'uStatus',title:'是否可用',width:180,align:'center',
			  			formatter: function(value,row,index){
							if (row.uStatus==1){
								return "是";
							} else {
								return "否";
							}
						}
	
			  		},
			  		{field:'uRegisterTime',title:'添加时间',width:180,align:'center',
			  			formatter: function(value,row,index){
							return getDate(row.uRegisterTime.toString());
			  			}
			  		},
			  		{field:'updatetime',title:'修改时间',width:180,align:'center',
			  			formatter: function(value,row,index){
			  				if(row.updatetime!=""&&row.updatetime!=undefined){
			  					return getDate(row.updatetime.toString());
			  				}
			  			}	
			  		}]]
			
		}); 
//显示右键menu
		$('#userData').datagrid({
			 onRowContextMenu: function (e, rowIndex, rowData) {
				 e.preventDefault();
				 $('#userMenu').menu('show', {
						left: e.pageX,
						top: e.pageY
					});
			 }
		 });
		function menuHandler(item){
			var select=$('#userData').datagrid('getSelections');
			var uIds="[";
			if(item.name=="save"||item.name=="del"){
				if(select.length>0){
					for(var i=0;i++;i<select.length-1){
						uIds+=select[i].uId+",";
					}
					uIds+=select[select.length-1].uId+"]";
					var status=1;
					if(item.name=="save"){
						status=1;
					}else{
						status=-1;
					}
					$.post("user/updateUserStatus",{uIds:uIds,status:status},function(data){
						if(data==200){
							$.messager.show({
								title:'成功信息',
								msg:'操作成功.',
								timeout:4000,
								showType:'slide'
							});
							$('#userData').datagrid('reload');
						}else{
							$.messager.alert('异常信息','操作异常!','error');
						}
					});
				}else{
					$.messager.alert('提示信息','选择要操作的账号数据!','info');
				}
			}
		}
		function submitForm(){
			var fields=$("#searchForm").serializeArray();
			var params=0;//是否有参数
			$.each( fields, function(i, field){
				  if(field.value!=""){
					  params++;
				  }
				});
			if(params==0){
				$('#userData').datagrid('reload');
			}else{
				$('#userData').datagrid({
					url:'user/getUserListByExample',
					queryParams:{uId:fields[0].value,uName:fields[1].value,uEmail:fields[2].value}
				});
			}
		}
		
		</script>